<?php


namespace app\admin\system\controller;

use app\common\controller\BaseAdminController;
use app\model\SysMessages;

/**
 * 消息提示
 * Class MessagesController
 * @package app\admin\system\controller
 */
class MessagesController extends BaseAdminController
{
    public function getUnreadCount()
    {
        return $this->success(SysMessages::where([
            'receiver_id' => request()->uid,
            'status' => 0
        ])->count("*"));
    }

    public function getUnreadNew10()
    {
        $list = SysMessages::where([
            'receiver_id' => request()->uid,
            'status' => 0
        ])->order('id desc')
            ->limit(10)
            ->select();
        return $this->success($list);
    }

    /**
     * 全部已读
     */
    public function readOne()
    {
        $id = input('id');
        if ($id) {
            SysMessages::where([
                'receiver_id' => request()->uid,
                'id' => $id,
                'status' => 0
            ])->update([
                'status' => 1
            ]);
        }
        return $this->success();
    }

    /**
     * 全部已读
     */
    public function allRead()
    {
        SysMessages::where([
            'receiver_id' => request()->uid,
            'status' => 0
        ])->update([
            'status' => 1
        ]);
        return $this->success();
    }
}